/*
 * ZoomPanel.java
 *
 * 
 */
package it.luigiarpino.alt2jsim.netpanel.flat;


import it.luigiarpino.alt2jsim.network.Net;

import javax.swing.*;
import java.awt.*;

/**
 *
 * @author  Luigi Lorenzo Arpino 534/559
 */
public class ZoomPanel extends JPanel {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 3272317020817581200L;
	private JPanel jPanelSouthPanel;
    private JButton jButtonZoomIn;
    private JButton jButtonZoomOut;
    private JScrollPane jScrollPane;
    private GrafoPanel grafoPanel;
    private JLabel jLabelZoom;
    
    /** Creates a new instance of ZoomPanel */
    public ZoomPanel(Net net_) {
        super();
        try { 
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());     
    	} 
    	catch(Exception e) { }
        this.setLayout(new BorderLayout());
        this.jPanelSouthPanel=new JPanel(new FlowLayout());
        this.jButtonZoomIn=new JButton("Zoom In");
        this.jButtonZoomOut=new JButton("Zoom Out");
        this.jButtonZoomOut.setEnabled(false);
        this.jButtonZoomIn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zoomIn(evt);
            }
        });
        this.jButtonZoomOut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zoomOut(evt);
            }
        });
        this.jLabelZoom=new JLabel("100");
        this.jPanelSouthPanel.add(this.jLabelZoom);
        this.jPanelSouthPanel.add(new JLabel("%"));
        this.jPanelSouthPanel.add(this.jButtonZoomIn);
        this.jPanelSouthPanel.add(this.jButtonZoomOut);
        this.grafoPanel=new GrafoPanel(net_);
        this.jScrollPane=new JScrollPane(this.grafoPanel);
        this.add(this.jPanelSouthPanel,BorderLayout.SOUTH);
        this.add(this.jScrollPane,BorderLayout.CENTER);
    }
    
    
    private void zoomIn(java.awt.event.ActionEvent evt) {
        int zoom=0;
        try{
            zoom=Integer.valueOf(this.jLabelZoom.getText()).intValue();
        }
        catch(java.lang.Exception e){
            return;
        }
        this.jButtonZoomOut.setEnabled(true);
        this.jLabelZoom.setText(String.valueOf(zoom*2));
        int h=this.grafoPanel.getHeight()*2;
        int w=this.grafoPanel.getWidth()*2;
        this.grafoPanel.setPreferredSize(new Dimension(w,h));
        this.jScrollPane.setViewportView(this.grafoPanel);
        if(zoom==800){
            this.jButtonZoomOut.setEnabled(true);
            this.jButtonZoomIn.setEnabled(false);
            return;
        }
    }
    
    
    private void zoomOut(java.awt.event.ActionEvent evt) {
        int zoom=0;
        try{
            zoom=Integer.valueOf(this.jLabelZoom.getText()).intValue();
        }
        catch(java.lang.Exception e){
            return;
        }
        this.jButtonZoomIn.setEnabled(true);
        this.jLabelZoom.setText(String.valueOf(zoom/2));
        int h=this.grafoPanel.getHeight()/2;
        int w=this.grafoPanel.getWidth()/2;
        this.grafoPanel.setPreferredSize(new Dimension(w,h));
        this.jScrollPane.setViewportView(this.grafoPanel);
        if(zoom==200){
            this.jButtonZoomOut.setEnabled(false);
            this.jButtonZoomIn.setEnabled(true);
            return;
        }
    }

}//fine classe
